<!DOCTYPE html>
<html class="no-js" lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>通知管理界面</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--====== Favicon Icon ======-->
    <link rel="shortcut icon" href="assets/images/favicon.png" type="image/png">
    <!--====== Magnific Popup CSS ======-->
    <link rel="stylesheet" href="assets/css/magnific-popup.css">
    <!--====== Slick CSS ======-->
    <link rel="stylesheet" href="assets/css/slick.css">
    <!--====== Line Icons CSS ======-->
    <link rel="stylesheet" href="assets/css/LineIcons.css">
    <!--====== Bootstrap CSS ======-->
    <link rel="stylesheet" href="assets/css/bootstrap.min.css">
    <!--====== Default CSS ======-->
    <link rel="stylesheet" href="assets/css/default.css">
    <!--====== Style CSS ======-->
    <link rel="stylesheet" href="assets/css/style.css">

</head>
<body>
<!-- 导入页眉 -->
<div class="header"></div>

<!--====== 自定义代码开始 ======-->
<section id="about" class="about-area">
    <div class="container">

        <div>
            <h3 style="position: absolute;top: 400px;left: 3%;">系统通知管理</h3>
        </div>

        <!--====== 从这里开始 ======-->
        <div class="row col-md-8 offset-md-2" style="margin-top: 5%;" id="div_vue">
            <table class="table">
                <thead class="thead-dark">
                <tr>
                    <th scope="col">通知序列</th>
                    <th scope="col">发布人</th>
                    <th scope="col">发布时间</th>
                    <th scope="col">通知内容</th>
                    <th scope="col">发布状态</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="notification in notificationList">
                    <th scope="row">{{notification.notificationId}}</th>
                    <td>{{notification.userName}}</td>
                    <td>{{notification.notificationTimeStr}}</td>
                    <td><p style="display:none;">{{notification.notificationContent}}</p>
                        <button v-on:click="click1" :notification="notification.notificationContent" type="button" class="btn btn-info">显示通知信息</button>
                        </td>
                    <td>
                        <div v-if="notification.notificationStatus=== 0" style="">
                            未发布
                        </div>
                        <div v-else>
                            发布中
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
            <form action="" class="form-group">
                <div class="offset-4">
                    <nav aria-label="Page navigation example">
                        <ul class="pagination">
                            <li class="page-item">
                                <a class="page-link" href="#" aria-label="Previous">
                                    <span aria-hidden="true" v-on:click="backward">&laquo;</span>
                                    <span class="sr-only">Previous</span>
                                </a>
                            </li>
                            <li class="page-item"><a v-on:click="firstPage" class="page-link" href="#">首页</a></li>
                            <input id="input" type="text" class="col-sm-2" style="border-color: rgb(222,226,230);" >
                            <button type="button" class="btn btn-primary" v-on:click="jump"  >跳转到/页</button>
                            <li class="page-item"><a v-on:click="lastPage" class="page-link" href="#">尾页</a></li>
                            <li class="page-item">
                                <a class="page-link" href="#" aria-label="Next">
                                    <span aria-hidden="true" v-on:click="forward">&raquo;</span>
                                    <span class="sr-only">Next</span>
                                </a>
                            </li>
                        </ul>
                    </nav>
                </div>
            </form>
        </div>
        <form>
            <div class="container-fluid">
                <div class="col-md-7 offset-2">
                    <div class="form-group" style="margin-bottom: 10px">
                        <label for="notificationContent">添加通知：</label>
                        <input type="text" class="form-control" name="notificationContent" id="notificationContent"
                               aria-describedby="emailHelp"
                               placeholder="notificationContent">
                    </div>
                    <button type="submit" class="btn btn-primary" onclick="addNotification()">添加</button>
                </div>
            </div>
        </form>
        <form id="form_notificationId">
            <div class="container-fluid" style="margin-top: 20px">
                <div class="col-md-4 offset-2">
                    <div class="form-group" style="margin-bottom: 10px">
                        <label for="notificationId1">发布通知：</label>
                        <div style="margin-bottom: 10px">
                            <input type="number" class="form-control" name="notificationId1" id="notificationId1"
                                   aria-describedby="emailHelp" placeholder="请输入通知id">
                        </div>
                        <div>
                            <input type="number" class="form-control" name="notificationId2" id="notificationId2"
                                   aria-describedby="emailHelp" placeholder="请输入通知id">
                        </div>

                    </div>
                    <button type="button" class="btn btn-primary" onclick="publish()">发布</button>
                </div>
            </div>
        </form>
        <!--====== 导入右边导航栏 ======-->
        <div class="admin-nav"></div>
        <!--====== 从这里结束 ======-->
    </div> <!-- container -->

</section>
<!--====== 自定义代码结束 ======-->


<!-- 导入页脚 -->
<div class="footer"></div>
<!--导入所有js文件-->
<!--====== Jquery js ======-->
<script src="assets/js/vendor/jquery-1.12.4.min.js"></script>
<script src="assets/js/vendor/modernizr-3.7.1.min.js"></script>
<!--====== Bootstrap js ======-->
<script src="assets/js/popper.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<!--====== Slick js ======-->
<script src="assets/js/slick.min.js"></script>
<!--====== Magnific Popup js ======-->
<script src="assets/js/jquery.magnific-popup.min.js"></script>
<!--====== Ajax Contact js ======-->
<script src="assets/js/ajax-contact.js"></script>
<!--====== Isotope js ======-->
<script src="assets/js/imagesloaded.pkgd.min.js"></script>
<script src="assets/js/isotope.pkgd.min.js"></script>
<!--====== Scrolling Nav js ======-->
<script src="assets/js/jquery.easing.min.js"></script>
<script src="assets/js/scrolling-nav.js"></script>
<!--====== Main js ======-->
<script src="assets/js/main.js"></script>
<!--导入vue 包-->
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<!--导入工具类-->
<script src="assets/js/util/HttpUtil.js"></script>
<script src="assets/validation-1.19.2/jquery.validate.min.js"></script>
<script src="assets/validation-1.19.2/localization/messages_zh.min.js"></script>
</body>
</html>
<script type="text/javascript">
    //在js中引入页眉页脚
    $(document).ready(function () {
        $('.header').load('header.html');
        $('.footer').load('footer.html');
        $('.admin-nav').load('admin-nav.html');
    });
    $(function () {
        check();
    });

    //校验输入内容
    function check() {
        $("#form_notificationId").validate(
            {
                rules: {
                    notificationId1: {required: true},
                    notificationId2: {required: true}
                },
                messages: {
                    notificationId1: {
                        required: "如需发布，请务必填写哦！",
                    },
                    notificationId2: {
                        required: "如需发布，请务必填写哦！",
                    }
                }
            }
        )
    }

    function publish() {
        //请求服务器，将所有通知状态清0，传递参数->通知id，将输入id状态置1
        let url = "changeStatus.do";
        var id1 = $("#notificationId1").val();
        var id2 = $("#notificationId2").val();
        console.log(id1);
        console.log(id2);
        let params = {id1: id1, id2: id2};
        console.log(params);
        doCasualPost(url, function (data) {
            alert(data);
        }, params)
    }


    function addNotification() {
        //请求服务器，传递参数，添加通知
        let url = "addNotification.do";
        var notificationContent = $("#notificationContent").val();
        console.log(notificationContent);
        let params = {content: notificationContent};
        console.log(params);
        doCasualPost(url, function (data) {
            alert(data);
        }, params);
    }

    let vm = new Vue({
        el: '#div_vue',
        data: {
            notificationList: []
        },
        methods: {
            // refreshNotificationList: function () {
            //     //发起http请求后台获取商家列表数据
            //     let url = "notificationShowAll.do";
            //     let thisObj = this;
            //     doGet(url, function (data) {
            //         thisObj.notificationList = data;
            //     })
            // },
            // click:function (e) {
            //     var target = e.target;
            //     alert($(target).attr("notification"));
            // },
            firstPage: function () {
                var url = "notificationShowAll.do";
                console.log("首页");
                let parm = {a: 0, b: 1};
                let thisObj = this;
                getWithParams(url, parm, function (data) {
                    console.log(data);
                    thisObj.notificationList = data;
                })
            },

            backward: function () {
                console.log("后退函数");
                url = "notificationShowAll.do";
                let parm = {a: 1, b:-168};
                let thisObj = this;
                getWithParams(url, parm, function (data) {
                    console.log(data);
                    thisObj.notificationList = data;
                })
            },
            forward: function () {
                console.log("前进函数");
                let url = "notificationShowAll.do";
                let parm = {a: 0, b: -168};
                let thisObj = this;
                getWithParams(url, parm, function (data) {
                    console.log(data);
                    thisObj.notificationList = data;
                });
            },
            jump:function(){
                console.log("页码跳转");
                let url = "notificationShowAll.do";
                let b = $("#input").val();
                let parm = {a: 0, b: b};
                let thisObj = this;
                getWithParams(url, parm, function (data) {
                    console.log(data);
                    thisObj.notificationList = data;
                });
            },
            lastPage: function () {
                console.log("尾页");
                let url = "lastNotification.do";
                let thisObj = this;
                doGet(url, function (data) {
                    console.log(data);
                    thisObj.notificationList = data;
                });
            },
            click1:function (e) {
                var target = e.target;
                alert($(target).attr("notification"));
            },
        },
        mounted: function () {
            //页面加载完成，并且vue对象加载完成之后调用
            this.firstPage();

        },
        created: function () {
            console.log("created");
        }
    });
</script>